package com.woniu.car.feigncontroller;

import com.woniu.car.common.ResponseEntity;
import com.woniu.car.exception.ParamException;
import com.woniu.car.parameter.AddUserInfoParam;
import com.woniu.car.service.TUserInfoService;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * Description:
 * date: 2021/6/29 19:55
 *
 * @author zhoubinbin
 * @since
 */
@RestController
@RequestMapping("/UserInfo")
public class UserController {
    @Resource
    private TUserInfoService userInfoService;
    @PostMapping("addUserInfo")
    public ResponseEntity addUserInfo(@Valid @RequestBody AddUserInfoParam addUserInfoParam, BindingResult bindingResult){
        for (ObjectError error : bindingResult.getAllErrors()) {
            return new ResponseEntity(500,"参数错误",error.getDefaultMessage());
        }
        return userInfoService.addUserInfo(addUserInfoParam);
    }
    @GetMapping("selectUserInfoByUserId")
    public ResponseEntity selectUserInfoByUserId(Integer userId) throws Exception {
        if (userId==null){
            throw new ParamException("用户id不能为空");
        }
        return userInfoService.getUserInfo(userId);
    }
}
